package com.study.shengsiyuan.example06;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
 * 	接口泛型  :  就是你要处理的数据类型
 * @author Administrator
 *
 */
public class MyProtobufServerHandler extends SimpleChannelInboundHandler<MyDataInfo.MyMessage> {

	@Override
	protected void channelRead0(ChannelHandlerContext ctx, MyDataInfo.MyMessage msg) throws Exception {
		MyDataInfo.MyMessage.DataType dataType =msg.getDataType();
		if(dataType==MyDataInfo.MyMessage.DataType.PersonType) {
			MyDataInfo.Person p = msg.getPerson();
			System.out.println(p.getName()+";"+p.getAge()+";"+p.getAddress());
		}else if(dataType==MyDataInfo.MyMessage.DataType.DogType) {
			MyDataInfo.Dog d= msg.getDog();
			System.out.println(d.getName()+";"+d.getAge());
		}else {
			MyDataInfo.Cat c= msg.getCat();
			System.out.println(c.getName()+";"+c.getCity());
		}


	}

	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
		ctx.channel().close();
	}
}
